﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using saigonbook.Dal;

namespace saigonbook.Biz
{
    public class BIZ_nhaxuatban
    {
        public int manhaxuatban;
        public string tennhaxuatban;
        public string diachi;
        public string sodienthoai;
        public string email;
        public int Maxnhaxuatban
        {
            get { return manhaxuatban; }
            set { manhaxuatban = value; }
        }
        public string Tennhaxuatban
        {
            get { return tennhaxuatban; }
            set { tennhaxuatban = value; }
        }
        public string Sodienthoai
        {
            get { return sodienthoai; }
            set { sodienthoai = value; }
        }
        public string Diachi
        {
            get { return diachi; }
            set { diachi = value; }
        }
        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        public BIZ_nhaxuatban()
        { }
        public BIZ_nhaxuatban(int manhaxuatban, string tennhaxuatban, string diachi, string sodienthoai, string email)
        {
            this.manhaxuatban = manhaxuatban;
            this.tennhaxuatban = tennhaxuatban;
            this.diachi = diachi;
            this.sodienthoai = sodienthoai;
            this.email = email;
        }

        public static List<BIZ_nhaxuatban> Select_NhaXuatBan()
        {
            return DAL_sach.Select_NhaXuatBan();
        }

        public static int laymanhaxuatban()
        {
            int ma = 0;
            List<BIZ_nhaxuatban> ds = DAL_sach.Select_NhaXuatBan();
            ds = (from nxb in ds
                  orderby nxb.manhaxuatban descending
                  select nxb).Take(1).ToList();
            foreach (BIZ_nhaxuatban n in ds)
            {
                ma = n.manhaxuatban + 1;
                break;
            }
            return ma;
        }

        public static bool kiemtratrungtennxb(BIZ_nhaxuatban nxb)
        {
            List<BIZ_nhaxuatban> ds = DAL_sach.Select_NhaXuatBan();
            foreach (BIZ_nhaxuatban l in ds)
            {
                if (l.manhaxuatban != nxb.manhaxuatban && l.tennhaxuatban.ToLower().Equals(nxb.tennhaxuatban.ToLower()))
                    return true;
            }
            return false;
        }

        public static List<BIZ_nhaxuatban> Search_NhaXuatBan(string ten)
        {
            return DAL_sach.Search_NhaXuatBan(ten);
        }

        public static void Them_NhaXuatBan(BIZ_nhaxuatban dto)
        {
            DAL_sach.Them_NhaXuatBan(dto);
        }

        public static void Sua_NhaXuatBan(BIZ_nhaxuatban dto)
        {
            DAL_sach.Sua_NhaXuatBan(dto);
        }

        public static bool kiemtraxoa(BIZ_nhaxuatban nxb)
        {
            List<BIZ_sach> ds = DAL_sach.Select_sach(nxb);
            foreach (BIZ_sach s in ds)
                if (nxb.manhaxuatban == s.nhaxuatban.manhaxuatban)
                    return false;
            return true;
        }

        public static void Xoa_nhaxuatban(BIZ_nhaxuatban nxb)
        {
            DAL_sach.Xoa_nhaxuatban(nxb);
        }
    }
}
